/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.Date;
import java.util.List;
import queenb.net.entitybean.C050;
import queenb.web.store.C050Store;
import queenb.web.util.ContextUtil;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class C050Controller extends QueenbController {

    private int pc050;
    private String cv051;
    private String cv052;
    private Date cd053;
    private Date cd054;
    private C050Store c050Store;

    public C050Controller() {
        c050Store = new C050Store();

        Object actionObject = getRequest().getParameter("action");
        if (actionObject != null) {
            if (actionObject.equals("edit")) {
                Object pc050Object = getRequest().getParameter("pc050");
                if (pc050Object != null) {
                    pc050 = Util.parseInt(pc050Object);
                    getDetailEditC050(pc050);
                }
            }
        }
    }

    public void getDetailEditC050(int id) {
        try {
            List<C050> listF000Edit = getListAllN000();
            if (listF000Edit.size() > 0) {
                for (int i = 0; i < listF000Edit.size(); i++) {
                    if (listF000Edit.get(i).getPc050() == id) {
                        this.cv051 = listF000Edit.get(i).getCv051();
                        this.cv052 = listF000Edit.get(i).getCv052();
                        this.cd053 = listF000Edit.get(i).getCd053();
                        this.cd054 = listF000Edit.get(i).getCd054();
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }

    public void updateC050() {
        try {

            String dateStart = ContextUtil.getRequestParameter("from");
            if (!dateStart.equals("")) {
                cd053 = Util.parseDate(dateStart, "dd/MM/yyyy");
            } else {
                cd053 = null;
            }

            String dateStart1 = ContextUtil.getRequestParameter("to");
            if (!dateStart1.equals("")) {
                cd054 = Util.parseDate(dateStart1, "dd/MM/yyyy");
            } else {
                cd054 = null;
            }
            int count = c050Store.updateC050(pc050, getLogin().getModule(), getLogin().getCompanyNo(), cv051, cv052, Util.toSQLDate(this.cd053), Util.toSQLDate(this.cd054), getLogin().getUserName());
            if (count > 0) {
                showGlobalReport(true, getResourceString("success"));
            } else {
                showGlobalReport(true, getResourceString("error"));
            }


            sendRedirectUrlTab("setting.jsp?tab=header13&llinkC050="+Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    public List<C050> getListAllN000() {

        try {

            List<C050> list = c050Store.getListC050(getLogin().getModule(), getLogin().getCompanyNo(), Util.toSQLDate("01/10/2012", "dd/MM/yyyy"), Util.toSQLDate("01/10/2014", "dd/MM/yyyy"), getLogin().getUserName());
            return list;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }

    /**
     * @return the pc050
     */
    public int getPc050() {
        return pc050;
    }

    /**
     * @param pc050 the pc050 to set
     */
    public void setPc050(int pc050) {
        this.pc050 = pc050;
    }

    /**
     * @return the cv051
     */
    public String getCv051() {
        return cv051;
    }

    /**
     * @param cv051 the cv051 to set
     */
    public void setCv051(String cv051) {
        this.cv051 = cv051;
    }

    /**
     * @return the cv052
     */
    public String getCv052() {
        return cv052;
    }

    /**
     * @param cv052 the cv052 to set
     */
    public void setCv052(String cv052) {
        this.cv052 = cv052;
    }

    /**
     * @return the cd053
     */
    public Date getCd053() {
        return cd053;
    }

    /**
     * @param cd053 the cd053 to set
     */
    public void setCd053(Date cd053) {
        this.cd053 = cd053;
    }

    /**
     * @return the cd054
     */
    public Date getCd054() {
        return cd054;
    }

    /**
     * @param cd054 the cd054 to set
     */
    public void setCd054(Date cd054) {
        this.cd054 = cd054;
    }
}
